home *** CD-ROM | disk | FTP | other *** search
/ Aminet 33 / Aminet 33 - October 1999.iso / Aminet / dev / basic / ASLmultiSelect.lha / ASLmultiSelect.asc
Encoding:
Text File  |  1999-08-22  |  4.1 KB  |  133 lines

  1. ;ASL Multi-select file requester subroutine
  2.  
  3. ;Original ASL File Requester code by Paul Burkey
  4. ;Multi-selection added by Curt Esser
  5.  
  6. ;last modified Aug 21 1999
  7.  
  8. ;it remembers the last user-set size & position
  9. ;for future calls
  10.  
  11. ;Sorry - too much stuff would need to be "shared"
  12. ;to make this practical in a Function
  13.  
  14. ;it also works with the ReqTools patch installed
  15. ;but the size & position settings are ignored
  16.  
  17. ;NOTE: you MUST use the ORIGINAL amigalibs.res file
  18. ;there is something wrong with the version that comes with
  19. ;Freds NCS - it doesn't return the correct fr_NumArgs
  20.  
  21. WBStartup
  22. WBenchToFront_
  23. FindScreen 0
  24. *scr.Screen=Peek.l(Addr Screen(0))
  25.  
  26. ;setup some defaults for the AslFilerequester
  27.  
  28. percentx.q = .36                       ;% of screen width to use
  29. percenty.q = .65                       ;% of screen height to use
  30. domulti.w  = 1                         ;0 for no multi-selection
  31. title$     = "ASL multi TEST"          ;requester title text
  32. doit$      = "Load"                    ;text for OK gadget
  33. filename$  = ""                        ;initial default file
  34. pathname$  = "RAM:"                    ;initial default path
  35.  
  36. rqwidth.w  = *scr\Width * percentx     ;calculate initial width
  37. rqheight.w = *scr\Height* percenty     ;calculate initial height
  38. rqleft.w   = *scr\Width/2 - rqwidth/2  ;calculate initial x position
  39. rqtop.w    = *scr\Height/2- rqheight/2 ;calculate initial y position
  40.  
  41.  
  42. NEWTYPE.files                          ;for the selections list
  43.   pathname.s
  44. End NEWTYPE
  45.  
  46. Dim List Selections.files(500)         ;or more if you need to...
  47.                                        ;if more than the dimensioned
  48.                                        ;amount of files are selected
  49.                                        ;the excess selected files
  50.                                        ;will simply be ignored
  51.  
  52. ;=====================================================================
  53.  
  54. ;the demo loop
  55.  
  56. Repeat
  57.   ClearList Selections()
  58.   Gosub filerequest
  59.   NPrint " "
  60.   NPrint "Selected ",selected.l     ;selected = number of files
  61.   ResetList Selections()
  62.   While NextItem(Selections())      ;each item in the list
  63.     NPrint Selections()\pathname    ;is a string with the full
  64.                                     ;pathname of a selected file
  65.   Wend
  66. Until f$="" OR ok.l=0  ;requester was cancelled or failed to open
  67.  
  68. End
  69.  
  70.  
  71. ;=====================================================================
  72.  
  73.  
  74. filerequest
  75.  
  76.   Dim Tags.TagItem(11)
  77.   Tags(0)\ti_Tag =#ASLFR_Screen,*scr
  78.   Tags(1)\ti_Tag =#ASLFR_PositiveText,&doit$
  79.   Tags(2)\ti_Tag =#ASLFR_RejectIcons,-1
  80.   Tags(3)\ti_Tag =#ASLFR_TitleText,&title$
  81.   Tags(4)\ti_Tag =#ASLFR_InitialFile,&filename$
  82.   Tags(5)\ti_Tag =#ASLFR_InitialDrawer,&pathname$
  83.   Tags(6)\ti_Tag =#ASLFR_InitialLeftEdge,rqleft
  84.   Tags(7)\ti_Tag =#ASLFR_InitialTopEdge,rqtop
  85.   Tags(8)\ti_Tag =#ASLFR_InitialWidth,rqwidth
  86.   Tags(9)\ti_Tag =#ASLFR_InitialHeight,rqheight
  87.   Tags(10)\ti_Tag=#ASLFR_DoMultiSelect,domulti
  88.   Tags(11)\ti_Tag=#TAG_END,0
  89.  
  90.   *filereq.FileRequester=AllocAslRequest_(#ASL_FileRequest,&Tags(0))
  91.   If *filereq
  92.     ok.l=AslRequest_(*filereq,&Tags(0))
  93.     If ok
  94.       f$=Peek.s(*filereq\fr_Drawer)
  95.       If f$<>""
  96.         If Right$(f$,1)<>":" AND Right$(f$,1)<>"/" Then f$=f$+"/"
  97.       EndIf
  98.       pathname$=f$                      ;the full path
  99.  
  100.       filename$=Peek.s(*filereq\fr_File);the file name
  101.  
  102.       selected.l= *filereq\fr_NumArgs   ;number of files selected
  103.  
  104.       If selected>1                     ;multiple files were selected
  105.  
  106.         For i = 0 To selected -1
  107.           *nextarg.l=Peek.l(*filereq\fr_ArgList+(8*i)+4)
  108.           If AddItem(Selections())
  109.             Selections()\pathname=pathname$+Peek.s(*nextarg)
  110.           EndIf
  111.         Next
  112.  
  113.       Else                              ;one or less selected
  114.  
  115.         If AddItem(Selections())
  116.           Selections()\pathname=pathname$+filename$
  117.         EndIf
  118.  
  119.       EndIf
  120.  
  121.       rqwidth =*filereq\fr_Width        ;save the user set positions
  122.       rqheight=*filereq\fr_Height       ;and sizes for next time
  123.       rqleft  =*filereq\fr_LeftEdge
  124.       rqtop   =*filereq\fr_TopEdge
  125.  
  126.     EndIf
  127.  
  128.     FreeAslRequest_(*filereq)           ;don't forget to free it!
  129.  
  130.   EndIf
  131.  
  132. Return
  133.